package com.chase.springboot.controller;

import com.chase.springboot.mapper.RoleMenuMapper;
import com.chase.springboot.model.Menu;
import com.chase.springboot.model.Role;
import com.chase.springboot.service.RoleMenuService;
import com.chase.springboot.service.RoleService;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("角色-菜单管理")
@RestController
public class RoleMenuController {
    @Autowired
    private RoleMenuService roleMenuService;

    @ApiOperation("查询角色有权限的菜单")
    @GetMapping("/role-menu/{roleId}")
    public List<Menu> insertUser(@PathVariable("roleId")Integer roleId){
        return roleMenuService.getMenusByRoleId(roleId);
    }
    @ApiOperation("添加角色有权限的菜单")
    @PostMapping("/role-menu/{menuId}/{roleId}")
    public Boolean addMenuToRole(@PathVariable("menuId")Integer menuId,
                           @PathVariable("roleId")Integer roleId){
        return roleMenuService.addMenuToRole(menuId, roleId);
    }
    @ApiOperation("删除角色有权限的菜单")
    @DeleteMapping("/role-menu/{roleId}")
    public Boolean deleteMenuInRole(@PathVariable("roleId")Integer roleId){
        return roleMenuService.deleteMenuInRole(roleId);
    }
}
